package vn.edu.vnu.sort;

import vn.edu.vnu.sort.R;

import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ProgressBar;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {
	private Handler progressBarHandler = new Handler();
	int progressBarStatus = 0;
	ProgressBar progressBar = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        progressBar = (ProgressBar) findViewById(R.id.progressBar1);
        progressBar.setProgress(0);
        progressBar.setMax(100);
        
        new Thread(new Runnable() {
			public void run() {
				while (progressBarStatus < 100) {

					try {
						Thread.sleep(50);
						progressBarStatus ++;
					} catch (InterruptedException e) {
						e.printStackTrace();
					}

					// Update the progress bar
					progressBarHandler.post(new Runnable() {
						public void run() {
							progressBar.setProgress(progressBarStatus);
						}
					});
				}

				Intent intent = new Intent();
    			intent.setClassName("vn.edu.vnu.sort", "vn.edu.vnu.sort.Choosing");
    			startActivity(intent);
			}
		}).start();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
 
        switch (item.getItemId())
        {
        case R.id.menu_settings:
        	Intent intent = new Intent();
			intent.setClassName("vn.edu.vnu.sort", "vn.edu.vnu.sort.Choosing");
			startActivity(intent);
            return true;
 
        default:
            return super.onOptionsItemSelected(item);
        }
    }    
}
